#!/usr/bin/env python
# -*- coding: utf-8 -*-

import csv
import sqlite3
import time

import sys
import os
import math
import pickle

basededados = '/home/admin1/estiglp1112-5140-python/basedados.db'
        

def criar_bd():

    conn = sqlite3.connect('basedados.db')

    c = conn.cursor()
    c.execute('''drop table if exists profs''')
    c.execute('''create table profs (id integer, 
              nome text, grau text, curso text, categoria text, regimeDeTempo text,
              anoLecivo text, tipoDeEnsino text, nomeDoEstabelecimento)''')
    conn.commit()
    ##spamReader = csv.reader(open('reb0.csv', 'rb'), delimiter=',')

    for count in range(0,10):

        spamReader = csv.reader(open('reb' + str(count) + '.csv', 'rb'), delimiter=',')
        
        count += 1

        spamReader.next()
        
        for row in spamReader:

            c.execute('''insert into profs values ("{0}","{1}","{2}","{3}","{4}","{5}","{6}","{7}", "{8}") '''.format(row[0].replace('"','_'),
                                        row[1].replace('"','_'), row[2].replace('"','_'), row[3].replace('"','_'), row[4].replace('"','_'),
                                        row[5].replace('"','_'), row[6].replace('"','_'), row[7].replace('"','_'), row[8].replace('"','_')))
            pass

    conn.commit()
    conn.close()

    
    print "Base de dados criada"
    
pass


##------------ ESTAtISTICAS-----------------------

##def lista_basedados():
##    conn = sqlite3.connect("basedados.db")
##    c = conn.cursor()
##
##    c.execute(''' select * from profs ''')
##    lista = []
##    for i in c.fetchall():
##        lista.append(i)
##        pass
##    c.close()           
##    return lista



def search_teacher_establisment_year_to_file(lista_basedados):

    conn = sqlite3.connect('basededados.db')
    c = conn.cursor()

    c.execute("""SELECT ano FROM docente""")

    consulta_ano = cursor.fetchall()
    
    cursor.close()

    print len (search_teacher_establisment_year_to_file)
    pass



    

##
##def search_teacher_establisment_year_to_file(lista_basedados):
##    
##    for row in lista_basedados:
##        
##        print row
##        pass
##    pass


